import React, { PureComponent } from "react";



export default class Son extends PureComponent {
  
  constructor(props){
    super(props);
    console.log("constructor");


    this.state = {
      age:20,
      name:"",
      sex:"",
      address:{
        province:"陕西省",
        city:"西安"
      }
    }
  }

  changeAge=()=>{
    this.setState({
      age:this.state.age+1
    })
  }

  changeCity=()=>{
    
    this.setState({
      address:{
        ...this.state.address,
        city:"北京"
      }
    })

  }

  render() {
    console.log("render");
    return (
      <div>
        <h1>子组件</h1>
        <p>年龄：{this.state.age}</p>
        <input type="button" value="修改年龄" onClick={this.changeAge} />
        <p>this.props.weight：{this.props.weight}</p>
        <hr/>
        <p>所在城市：{this.state.address.city}</p>
        <input type="button" value="修改城市" onClick={this.changeCity} />
      </div>
    );
  }
}


